﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Citi.RoutineBase;
using Citi.GocAttributes.Domain;
using System.Configuration;

namespace Citi.GocAttributes.SchedulerUI
{
    public class GocAttributesReportGeneration : IExecutableRoutine
    {
        protected string GocAttributesPathToSave { get { return ConfigurationManager.AppSettings["GocAttributesPathToSave"]; } }

        public IEnumerable<RoutineParameter> Parameters
        {
            get
            {
                return new List<RoutineParameter>{ 
                   new RoutineParameter{ Description= "Reference month to generate report. Default: Current Month", Name ="Month", Nullable = true, Required = false, Type = typeof(short)},
                   new RoutineParameter{ Description= "Reference year to generate report. Default: Current Year", Name ="Year", Nullable = true, Required = false, Type = typeof(short)}
                   };
            }
        }

        public void Rollback(ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {

        }

        public void Start(DateTime scheduledDate, ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            var month = parameters.ContainsKey("Month") ? int.Parse(parameters["Month"].ToString()) : DateTime.Today.Month;
            var year = parameters.ContainsKey("Year") ? int.Parse(parameters["Year"].ToString()) : DateTime.Today.Year;

            currentAction.Description = "Generating GOC Attributes Report";

            var file = new Goc().GenerateReport(new DateTime(year, month, 1), GocAttributesPathToSave);

            currentAction.Description = string.Format("Report generated. Path: {0}", file);
        }

        public void Stop(ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {

        }
    }
}
